import { ApiRes, BannerItem, GoodItem, HotGoodItem, Brand, HomeProduct, Special } from '@/types/data'
import request from '@/utils/request'
import { defineStore } from 'pinia'

const useHomeStore = defineStore('home', {
	state: () => {
		return {
			bannerList: [] as BannerItem[],
			newGoodList: [] as GoodItem[],
			hotGoodList: [] as HotGoodItem[],
			// 品牌数据
			brandList: [] as Brand[],
			productList: [] as HomeProduct[],
			specialList: [] as Special[],
		}
	},
	actions: {
		async getBannerList() {
			const res = await request.get<ApiRes<BannerItem[]>>('/home/banner')
			this.bannerList = res.data.result
		},
		async getNewList() {
			const res = await request.get<ApiRes<GoodItem[]>>('/home/new')
			this.newGoodList = res.data.result
		},
		async getHotList() {
			const res = await request.get<ApiRes<HotGoodItem[]>>('/home/hot')
			this.hotGoodList = res.data.result
		},
		async getBrandList() {
      const res = await request.get<ApiRes<Brand[]>>('/home/brand')
      this.brandList = res.data.result
		},
		async getProductList() {
      const res = await request.get<ApiRes<HomeProduct[]>>('/home/goods')
      this.productList = res.data.result
		},
		async getSpecialList() {
      const res = await request.get<ApiRes<Special[]>>('/home/special')
      this.specialList = res.data.result
    }
	},
})

export default useHomeStore
